package com.fau.wmbj.server.controller;

import cn.hutool.core.collection.CollectionUtil;
import com.fau.wmbj.server.config.CurrentUser;
import com.fau.wmbj.server.entity.OrderMember;
import com.fau.wmbj.server.entity.User;
import com.fau.wmbj.server.service.OrderMemberService;
import com.fau.wmbj.server.service.OrderService;
import com.fau.wmbj.server.utils.Filter;
import com.fau.wmbj.server.utils.Message;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
import java.util.List;
import java.util.Map;

/**
 * 订单成员
 *
 * @author jiawei
 * @version 1.0
 * @datetime 2024-04-16 16:36
 */
@RestController
@RequestMapping("/order-member")
public class OrderMemberController {

    @Resource
    private OrderMemberService orderMemberService;
    @Resource
    private OrderService orderService;

    /**
     * 根据订单Id查询订单成员
     */
    @RequestMapping("/getByOrderId")
    @ResponseBody
    public Message save(@RequestBody OrderMember orderMember, @CurrentUser User user) {
        Map<String, Object> params = orderMember.getParams();
        Integer orderId = (Integer) params.get("orderId");
        List<OrderMember> orderMemberList = orderMemberService.findList(Filter.eq("user", user), Filter.eq("order_.id", Long.valueOf(orderId)));
        return Message.success(CollectionUtil.isNotEmpty(orderMemberList) ? orderMemberList.get(0) : null);
    }


}
